import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'

Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'
const files = require.context('./modules', false, /\.js$/)
const modules = {}

files.keys().forEach(key => {
    modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
})
Object.keys(modules).forEach(key => {
    modules[key]['namespaced'] = true
})
const logger = createLogger({
    collapsed: true,
    filter(mutation) {
        return mutation.type !== 'keepAlive/updateKeepAliveList'
    }
})
const store = new Vuex.Store({
    modules,
    plugins: debug ? [logger] : []
})
export default store
